
package com.wyzz.hr.bo.impl;

import com.wyzz.hr.bo.IEmpJobHisBo;
import com.wyzz.hr.dao.IEmpJobHisDao;
import com.wyzz.hr.pojo.Emphistoryjob;
import com.wyzz.hr.pojo.Employee;

import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.criterion.*;


public class EmpJobHisBoImpl implements IEmpJobHisBo {

	public EmpJobHisBoImpl() {
	}

	public String insert(Emphistoryjob emphis) {
		empJobHisDao.saveObject(emphis);
		return emphis.getEhjId();
	}

	public List search(String employeeId) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Emphistoryjob.class);
		detachedCriteria.setFetchMode(Emphistoryjob.PROP_EMPLOYEE,
				FetchMode.DEFAULT);
		detachedCriteria.add(Restrictions.eq((new StringBuilder()).append(
				Emphistoryjob.PROP_EMPLOYEE).append(".").append(
				Employee.PROP_ID).toString(), employeeId));
		detachedCriteria
				.addOrder(Order.desc(Emphistoryjob.PROP_EHJ_DATE_START));
		List result = empJobHisDao.findByCriteria(detachedCriteria);
		return result;
	}

	public void delete(Emphistoryjob ehj) {
		empJobHisDao.deleteObject(ehj);
	}

	public void update(Emphistoryjob emphis) {
		empJobHisDao.saveOrupdate(emphis);
	}

	public List search(Emphistoryjob empHis) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Emphistoryjob.class);
		detachedCriteria.setFetchMode(Emphistoryjob.PROP_EMPLOYEE,
				FetchMode.DEFAULT);
		detachedCriteria.add(Restrictions.eq(Emphistoryjob.PROP_EHJ_ID, empHis
				.getEhjId()));
		detachedCriteria
				.addOrder(Order.desc(Emphistoryjob.PROP_EHJ_DATE_START));
		List emphisObj = empJobHisDao.findByCriteria(detachedCriteria);
		return emphisObj;
	}

	public IEmpJobHisDao getEmpJobHisDao() {
		return empJobHisDao;
	}

	public void setEmpJobHisDao(IEmpJobHisDao empJobHisDao) {
		this.empJobHisDao = empJobHisDao;
	}

	public Emphistoryjob load(String ehjId, String fetches[]) {
		return (Emphistoryjob) empJobHisDao.loadObject(
				com.wyzz.hr.pojo.Emphistoryjob.class, ehjId, fetches,
				new boolean[0]);
	}

	private IEmpJobHisDao empJobHisDao;
}
